1. Technical Field
The invention relates generally to optimizing code generation by compilers, and more particularly relates to code transforms for improved code generation in compilers for high level shader languages.
2. Description of Related Art
Computers commonly have a graphics adapter or graphics accelerator that contains a specialized microprocessor, generally known as a graphics co-processor or graphics processing unit (GPU). A GPU also can be integrated into the chip set contained on the motherboard of the computer. The GPU handles high-speed graphics-related processing to free the computer's central processing unit (CPU) for other tasks. Today's graphics adapters (e.g., various graphics adapter models available from NVIDIA and ATI Technologies, among others) feature GPUs that are specifically designed to render 3-dimensional (3D) graphics images and video at high frame rates, such as for use in computer games, video and other graphics intensive applications. Some CPUs for computers also include specialized instructions in their instruction sets that are designed for graphics-related processing (e.g., the MMX instructions in Intel Corporation microprocessors).
In past graphics adapters, the GPU generally provided fixed functionality for graphics processing operations. Application programs (e.g., a game with 3D graphics) would interact with the graphics adapter through a graphics application programming interface (API), such as Microsoft Corporation's DirectX®, and OpenGL® of Silicon Graphics, Inc. Through a graphics API, the application programs directed the GPU to execute its fixed graphics processing functions.
In its version 8, Microsoft DirectX® more recently introduced the concept of a programmable graphics shader for recent programmable graphics hardware. A shader is a program that executes on graphics hardware to perform graphics processing on a per pixel, or per vertex (or other graphics component or fragment) basis for 3D graphics rendering. DirectX® 8 included a language for writing shaders. However, this language was a low-level, assembly-like language and also very specific to certain GPU architectures. This made it more difficult for application developers to take advantage of this improved programmability of the graphics hardware.
DirectX® version 9 introduced a high level programming language for shaders (called the High Level Shading Language or HLSL) to make it easier for application developers to create shaders. The HLSL is syntactically similar to the well known C programming language. This makes it easier for programmers who are familiar with C to understand.
A problem arises, however, in that non- or less than optimal object code may result from compiling a high level language into object code of a target processor. Further, programmable GPUs are vector-based processors with different architectural constraints than conventional CPU processors. Accordingly, known code optimization techniques may still fail to produce more optimal code for shaders on programmable graphics hardware.
For example, a current typical programmable GPU provides a set of vector registers for loading textures from graphics memory. The textures are a set or array of values held in the graphics memory of the graphics adapter. Typically, the registers have capacity for four components of vector values pulled one at a time from an assigned texture in memory. The GPU executes texture load instructions that assign the texture to be loaded in the components of a register, and arithmetic instructions that operate on vectors of the texture. However, direct translation by a compiler of high level shader language instructions would result in shaders that fail to efficiently utilize the register architecture of these processors, and conventionally known compiler code optimizations are not designed to optimize this type of processor architecture.